package com.tiancheng.trade.payment.enums;

import com.tiancheng.trade.commom.core.enums.BaseEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 流水状态（支付、退款）
 *
 * @author supeicheng
 * @date 2024/3/4
 */
@Getter
@AllArgsConstructor
public enum FlowStatusEnum implements BaseEnum<String> {

    WAITING("wait", "处理中"),
    SUCCESS("success", "成功"),
    FAIL("fail", "失败"),
    PART_SUCCESS("part", "部分成功");

    private String code;
    private String desc;

    public static String getDesc(String code) {
        Optional<FlowStatusEnum> found = Arrays.stream(FlowStatusEnum.values()).filter(c -> c.code.equals(code)).findFirst();
        if (found.isPresent()) {
            return found.get().getDesc();
        }
        return "";
    }

    public static FlowStatusEnum getByCode(String code) {
        Optional<FlowStatusEnum> found = Arrays.stream(FlowStatusEnum.values()).filter(c -> c.code.equals(code)).findFirst();
        return found.orElse(null);
    }

}
